package com.squapsource.project_euler.utils;

import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;

public class Fibonacci {

	public static List<Long> getFibonacci(long maxValue) {
		if (maxValue < 3) {
			throw new InvalidParameterException("Value too small: " + maxValue);

		}
		List<Long> fibonaccis = new ArrayList<Long>();
		fibonaccis.add(1L);
		fibonaccis.add(1L);
		long nextNum = 2L;

		while (nextNum <= maxValue) {
			fibonaccis.add(nextNum);
			nextNum = fibonaccis.get(fibonaccis.size() - 2)
					+ fibonaccis.get(fibonaccis.size() - 1);
		}
		return fibonaccis;
	}

	public static List<Long> getFibonacciNumDigits(int numDigits) {
	
		List<Long> fibonaccis = new ArrayList<Long>();
		fibonaccis.add(1L);
		fibonaccis.add(1L);
		long nextNum = 2L;

		while (String.valueOf(nextNum).length() < numDigits) {
			fibonaccis.add(nextNum);
			nextNum = fibonaccis.get(fibonaccis.size() - 2)
					+ fibonaccis.get(fibonaccis.size() - 1);
		}
		fibonaccis.add(nextNum);
		return fibonaccis;
	}
}
